//
//  TestWindow.m
//  sandbox
//
//  Created by 杨岑 on 12/31/14.
//  Copyright (c) 2014 杨岑. All rights reserved.
//

#import "TestWindowWC.h"
#import "TestView.h"


@interface TestWindowWC ()
@property (weak) IBOutlet NSButton* button;
@end

@implementation TestWindowWC
{
    TestView* _testView;
}

- (instancetype)init
{
    self = [super initWithWindowNibName:@"TestWindow"];
    if (self)
    {
        _testView = self.window.contentView;
    }
    return self;
}

- (void)awakeFromNib
{
    //NSLog(@"awakeFromNib: %@", self);
}

- (IBAction)slider_change:(id)sender
{
    NSSlider* slider = sender;
    self.window.alphaValue = slider.floatValue;
}

- (IBAction)test_click:(id)sender
{
    NSLog(@"test_click: %@", self);
    
    static NSTimer* timer;
    if (!timer)
    {
        timer = [NSTimer timerWithTimeInterval:.1 target:self selector:@selector(timer_tick:) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    }
}

- (void)timer_tick:(NSTimer*)timer
{
    _testView.time += timer.timeInterval;
    
    if (_testView.time > 1.5)
    {
        NSLog(@"Pop!");
        _testView.time = 0;
    }
}

- (IBAction)close_click:(id)sender {
    [self.window close];
}

- (void)windowWillClose:(NSNotification *)notification
{
    [NSApp stopModal];
}

- (void)windowDidResignKey:(NSNotification *)notification
{
    self.window.isVisible = NO;
}

@end
